﻿/*
 * @author: wizardc
 */

#if UNITY_EDITOR

using UnityEngine;

namespace Dou.Controller
{
    /// <summary>
    /// 固定机位的摄像机调试器
    /// </summary>
    [RequireComponent(typeof(FixedCameraController))]
    public class FixedCameraDebugger : MonoBehaviour
    {
        private static readonly Color LimitColor = Color.red;
        private static readonly Color ViewPortTrapezoidColor = Color.green;
        private static readonly Color ViewPortRectColor = Color.yellow;
        private static readonly Color ScreenCenterColor = Color.cyan;
        private static readonly Color SpaceCenterColor = Color.magenta;
        
        private FixedCameraController _controller;
        
        void Awake()
        {
            _controller = GetComponent<FixedCameraController>();
        }

        void LateUpdate()
        {
            var limitPos = _controller.limitPos;
            var viewportPos = _controller.viewportPos;

            // 限制区域
            Debug.DrawLine(limitPos[0], limitPos[1], LimitColor);
            Debug.DrawLine(limitPos[1], limitPos[3], LimitColor);
            Debug.DrawLine(limitPos[3], limitPos[2], LimitColor);
            Debug.DrawLine(limitPos[2], limitPos[0], LimitColor);
            
            // 梯形
            Debug.DrawLine(viewportPos[0], viewportPos[1], ViewPortTrapezoidColor);
            Debug.DrawLine(viewportPos[1], viewportPos[3], ViewPortTrapezoidColor);
            Debug.DrawLine(viewportPos[3], viewportPos[2], ViewPortTrapezoidColor);
            Debug.DrawLine(viewportPos[2], viewportPos[0], ViewPortTrapezoidColor);

            // 矩形
            Debug.DrawLine(viewportPos[0], viewportPos[1], ViewPortRectColor);
            Debug.DrawLine(viewportPos[1], viewportPos[5], ViewPortRectColor);
            Debug.DrawLine(viewportPos[5], viewportPos[4], ViewPortRectColor);
            Debug.DrawLine(viewportPos[4], viewportPos[0], ViewPortRectColor);
            
            // 屏幕中心点
            var screenCenter = viewportPos[6];
            Debug.DrawLine(screenCenter + new Vector3(-3, 0, 0), screenCenter + new Vector3(3, 0, 0), ScreenCenterColor);
            Debug.DrawLine(screenCenter + new Vector3(0, 0, -3), screenCenter + new Vector3(0, 0, 3), ScreenCenterColor);
            
            // 空间中心点
            var spaceCenter = viewportPos[7];
            Debug.DrawLine(spaceCenter + new Vector3(-3, 0, 0), spaceCenter + new Vector3(3, 0, 0), SpaceCenterColor);
            Debug.DrawLine(spaceCenter + new Vector3(0, 0, -3), spaceCenter + new Vector3(0, 0, 3), SpaceCenterColor);
        }
    }
}

#endif